package com.wdy.ssafe;

import com.wdy.servicebase.utils.MD5;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

@Component
public class DefaultPasswordEncoder implements PasswordEncoder {

  public DefaultPasswordEncoder() {
  }

  @Override
  public boolean upgradeEncoding(String encodedPassword) {
    return false;
  }

  @Override
  public String encode(CharSequence rawPassword) {
    if (null == rawPassword) {
      throw new IllegalArgumentException("无法加密，字符串为空");
    }
    return MD5.encrypt(rawPassword.toString());
  }

  @Override
  public boolean matches(CharSequence rawPassword, String encodedPassword) {
    return encodedPassword.equals(this.encode(rawPassword));
  }
}
